import sys
from PyQt5 import QtWidgets
from PyQt5.QtCore import QStringListModel
from Window import Ui_Form
from PyQt5.QtWidgets import *
import xlrd, xlwt
import os


class myForm(QtWidgets.QWidget, Ui_Form):
    def __init__(self):
        super(myForm, self).__init__()
        self.setupUi(self)
        # signal connect
        self.openB.clicked.connect(self.openFile)
        self.list.clicked.connect(self.clickedList)

    # slot set
    def openFile(self):
        fileName, fileType = QFileDialog.getOpenFileName(self, "Choose File", os.getcwd() + "\..", "Sheet File(*.xls)")
        self.workbook = xlrd.open_workbook(fileName)
        slm = QStringListModel()
        self.thelist = self.workbook.sheet_names()
        slm.setStringList(self.thelist)  # # 添加的数组数据 将数据设置到model
        self.list.setModel(slm)  ##绑定 listView 和 model

    def clickedList(self, modoul):
        theSheet = self.thelist[modoul.row()]
        self.theSheet = self.workbook.sheet_by_name(theSheet)
        if self.theSheet.nrows==0:
            QMessageBox.information(self,"提示","空表")
        else:
            attList = self.theSheet.row_values(0,1,6)
            attModoul = QStringListModel()
            attModoul.setStringList(attList)
            self.attributeBox.setModel(attModoul)




if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    qtform = myForm()
    qtform.show()
    sys.exit(app.exec_())
